package com.wwj.depository.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wwj.depository.constant.ConstantFinal;
import com.wwj.depository.dao.DepositoryLocationDao;
import com.wwj.depository.entity.DepositoryLocationEntity;
import com.wwj.depository.service.DepositoryLocationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class DepositoryLocationServiceImpl extends ServiceImpl<DepositoryLocationDao, DepositoryLocationEntity> implements DepositoryLocationService {

    @Resource
    private DepositoryLocationDao depositoryLocationDao;
    /**
     * 根据分页和查询内容查询全部仓位数据
     */
    @Override
    public PageInfo<DepositoryLocationEntity> selectDepositoryData(String currentPage, String pageSize, String query) {
        Page<DepositoryLocationEntity> page = PageHelper.startPage(Integer.parseInt(currentPage), Integer.parseInt(pageSize));
        QueryWrapper<DepositoryLocationEntity> queryWrapper = new QueryWrapper<>();
        if (!query.isEmpty()){
            // 有查询条件，构建条件构造器
            queryWrapper.like(ConstantFinal.FIELD_LOCATION_NAME,query);
        }
        depositoryLocationDao.selectList(queryWrapper);
        return page.toPageInfo();
    }
}
